//
//  SSSSystemMessageViewController.m
//  SSSAllRollAgency
//
//  Created by xnxin on 2017/3/16.
//  Copyright (c) 2017 Darker. All rights reserved.
//

#import "SSSSystemMessageViewController.h"
#import "SSSSystemMessageCellModel.h"
#import "UIStoryboard+XHAdd.h"
#import "XHUIHelper.h"
#import "XHTableViewSection.h"
#import "SSSSystemMessageDetailViewContoller.h"
#import <QMUIKit/QMUIKit.h>
#import "APITool.h"
#import "NSDictionaryAdditions.h"

@interface SSSSystemMessageViewController ()

@end

@implementation SSSSystemMessageViewController

- (void)loadView {
    [super loadView];

    UIView *bgView = [XHUIHelper bgView];
    bgView.top = -64;
    [self.view insertSubview:bgView atIndex:0];
    self.tableView.backgroundColor = [UIColor clearColor];
}

- (void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.rowHeight = 103;
    self.title = @"系统消息";

//    UIImage *bgImage = [self imageWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64) alphe:0.3];
//    [self.navigationController.navigationBar setBackgroundImage:bgImage forBarMetrics:UIBarMetricsDefault];
}

- (NSArray<NSString *> *)nibNameArray {
    return @[@"SSSSystemMessageCell"];
}

- (NSString *)url {
   return [APITool urlStr:@"/bApi/systemMessage/list"];
}

- (BOOL)isSingleSection {
    return NO;
}

- (NSArray*)processData:(NSDictionary *)data {
    [self hideEmptyView];
    NSArray *modelArray = [NSArray modelArrayWithClass:[SSSSystemMessageCellModel class]
                                                  json:[data objectOrNilForKey:@"pageList"]];
    NSArray *sections = [XHTableViewSection sectionsWithArray:modelArray];
    return sections;
}

+ (SSSSystemMessageViewController *)storyboardInstance {
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"SystemMessage" bundle:nil];
    return [sb controller:self];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 15;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    SSSSystemMessageCellModel *model = [self.dataSource modelForIndexPath:indexPath];
    SSSSystemMessageDetailViewContoller *vc = [SSSSystemMessageDetailViewContoller storyboardInstance];
    vc.model = model;
    [self.navigationController pushViewController:vc animated:true];
}

@end
